home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / uip / send / s_gather.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  1.2 KB  |  69 lines

  1. /* name:
  2.     gather
  3.  
  4. function:
  5.     read a single line of console input into the user specified
  6.     buffer.
  7.  
  8. algorithm:
  9.     Read a character:
  10.     If it is an unescaped new line, null terminate the buffer and return.
  11.     Otherwise, stash the character into the buffer.
  12.     If the length of the buffer has been reached, echo a new line and
  13.     return.
  14.  
  15. parameters:
  16.     *char   pointer to user buffer of length S_BSIZE
  17.  
  18. returns:
  19.     nothing
  20.  
  21. globals:
  22.     S_BSIZE
  23.  
  24. calls:
  25.     getchar
  26.  
  27. called by:
  28.     main
  29.     send
  30.  
  31. */
  32. /*
  33. **    R E V I S I O N  H I S T O R Y
  34. **
  35. **    03/31/83  GWH    Split the SEND program into component parts
  36. **
  37. */
  38.  
  39. #include "./s.h"
  40. #include "./s_externs.h"
  41.  
  42. gather (sp, max)
  43. char   *sp;
  44. register int max;
  45. {
  46.     register int    c;
  47.     register char   *p;
  48.  
  49.     fflush (stdout);
  50.  
  51.     for (p = sp; max-- > 0; *p++ = c)
  52.     {
  53.     if ((c = getchar ()) == EOF)
  54.         if (ferror (stdin) || feof (stdin))
  55.         {                   /* something really happened            */
  56.         *p = '\0';
  57.         return (-1);
  58.         }
  59.  
  60.     c = toascii (c);        /* make sure it's valid                 */
  61.  
  62.     if (c == '\n')          /* normal end on newline                */
  63.         break;
  64.     }
  65.  
  66.     *p = '\0';
  67.     return (p - sp);              /* return length                      */
  68. }
  69.